package com.ddwl.message.dao;

import com.ddwl.common.dao.TkDao;
import com.ddwl.common.util.MySqlUtil;
import com.ddwl.message.mapper.MessageUserMapper;
import com.ddwl.message.model.MessageUser;
import com.ddwl.message.model.MessageUserList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
import java.util.Map;

@Repository
public class MessageUserDao extends TkDao<MessageUserMapper, MessageUser> {

    @Autowired
    private MessageUserMapper messageUserMapper;

    public List<MessageUserList> getListByUserId(String userId) {
        return messageUserMapper.getListByUserId(userId);
    }

    public void updateReadStatus(String messageId, String userId) {
        messageUserMapper.updateReadStatus(messageId, userId);
    }

    public List<MessageUser> getList(MessageUser messageUser) {
        Example example = getExample();
        example.and().andEqualTo("messageInfoId", messageUser.getMessageInfoId())
                .andLike("userName", MySqlUtil.rightLike(messageUser.getUserName()))
                .andLike("userPhone", MySqlUtil.rightLike(messageUser.getUserPhone()))
                .andLike("userId", MySqlUtil.rightLike(messageUser.getUserId()));
        return messageUserMapper.selectByExample(example);
    }

    public void deleteByMessageId(String messageId) {
        messageUserMapper.deleteByMessageId(messageId);
    }

    public void insertByList(List<MessageUser> list) {
        messageUserMapper.insertByList(list);
    }

    public List<MessageUserList> getHasRead(MessageUser messageUser){
        return messageUserMapper.getHasRead(messageUser);
    }

    public void changeMessageInfoId(Map<String, String> map) {
        messageUserMapper.changeMessageInfoId(map);
    }
}
